Public: Concord Software Projects : OTrunk Controllers
This page last changed on Jul 14, 2009 by sfentress.
OverviewOTrunk Controllers are used link OTrunk objects with Plain Old Java Objects (POJO). The are useful if you want to use OTrunk to configure and save data from java libraries which don't directly use OTrunk objects. There are 3 objects involved when an controller is used. The OTObject, the OTController, and the "RealObject"(POJO). Here is an example of how controllers can be used. There is a java library that supports graphing data. To supply data to the graph a DataProducer interface is implemented and the implementation is passed to the graph. For example lets say we want to provide a DataProducer that always supplies the same value: Create a OTClassMake a new java interface which extends OTObjectInterface For example: public interface OTMyObject extends OTObjectInterface { public String getMyString(); public void setMyString(String myString); } Create an OTControllerMake a new java class which implements OTController public class OTMyObjectController extends DefaultOTController { public static Class[] realObjectClasses = { MyObject.class }; public static Class otObjectClass = OTMyObject.class; public void loadRealObject(Object realObject) { MyObject myObject = (MyObject) realObject; OTMyObject otMyObject = (OTMyObject) otObject; // property:url myObject.setMyString(otMyObject.getMyString()); } public void registerRealObject(Object arg0) { // TODO Auto-generated method stub } public void saveRealObject(Object arg0) { // TODO Auto-generated method stub } } For each controller you need to do the following things: Declare classesDefine the following two public static fields: public static Class[] realObjectClasses = { MyObject.class }; public static Class otObjectClass = OTMyObject.class; Replace MyObject.class with the class this controller is working with. Implement loading codeImplement the "loadRealObject" method. It should get properties from the otObject field, and set them on Register ControllerThere needs to be a OTPackage in the same java package as the OTObject. The name of the OTPackage class In the initialize method add a call to register your new controller class: public void initialize(OTrunk otrunk) { // get controller registry and reistrer our controllers OTControllerRegistry registry = (OTControllerRegistry) otrunk.getService(OTControllerRegistry.class); registry.registerControllerClass(OTPasProjectController.class); registry.registerControllerClass(OTPasActivityController.class); registry.registerControllerClass(OTDisplayPageController.class); } |
Document generated by Confluence on Jan 27, 2014 16:52 |